package com.sumainfor.pc.gmio.service.impl;

import com.qiniu.util.Json;
import com.sumainfor.common.util.JsonResult;
import com.sumainfor.pc.gmio.dao.SeTemporaryMapper;
import com.sumainfor.pc.gmio.feign.Zfeign.ZpcMktFeign;
import com.sumainfor.pc.gmio.service.DiRepairService;
import com.sumainfor.pc.gmio.service.SeTemporaryService;
import org.apache.commons.collections.MapUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.locks.ReentrantLock;

/**
 * 临时账单
 */
@Service
public class SeTemporaryServiceImpl implements SeTemporaryService {

    private ReentrantLock lock = new ReentrantLock(false);
    Logger log = LoggerFactory.getLogger(SeTemporaryServiceImpl.class);
    @Autowired
    private SeTemporaryMapper seTemporaryMapper;
    @Autowired
    private ZpcMktFeign zpcMktFeign;
    /**
     * 租客端查询临时账单
     */
    public List<Map<String,Object>> getHouTemporaryList(Map<String,Object> params){
        List<Map<String,Object>> gmioList=seTemporaryMapper.getTemporaryList(params);
        List<String> houInfoIdList=new ArrayList<String>();
        for(Map<String,Object> map: gmioList){
            if (map.get("HouInfoId")!=null){
                houInfoIdList.add(map.get("HouInfoId").toString());
            }
        }
        params.put("houInfoIdList",houInfoIdList);
        //根据房源编号到市场部查询房源的信息
        JsonResult marketResult=zpcMktFeign.getHouTemporaryList(params);
        if (marketResult.get("errorCode").equals("0")) {
            //市场部的房源列表
            List<Map<String,Object>> mktlist=(List<Map<String,Object>>)marketResult.get("result");
            for (Map<String,Object> giomap : gmioList){
                for (Map<String,Object> mktmap : mktlist) {
                    if (MapUtils.getString(giomap, "HouInfoId").equals(MapUtils.getString(mktmap, "HouInfoId"))) {
                        giomap.putAll(mktmap);
                    }
                }
            }
        }
        return gmioList;
    }
}
